﻿using ET_DbCommon.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET_DbCommon.DAL
{
    public static class Exam_TestQuestionDAL
    {
        /// <summary>
        /// 创建考核关联的场景
        /// </summary>
        /// <param name="MyPaperId"></param>
        public static Task InsertToExam_TestQuestion(ExamModel MyexamModel, int MyPaperId)
        {
            try
            {
                using (var conn = MySqlHelper.GetConnection())
                {
                    var MyPaper_TestQuestionModel = Paper_TestQuestionDAL.GetMyPaper_TestQuestionModel(MyPaperId);
                    if (MyPaper_TestQuestionModel != null)
                    {
                        Exam_TestQuestionModel exam_TestQuestionModel = new Exam_TestQuestionModel();
                        exam_TestQuestionModel.TestName = MyPaper_TestQuestionModel.TestName;
                        exam_TestQuestionModel.CountDown = MyPaper_TestQuestionModel.CountDown;
                        exam_TestQuestionModel.Describes = MyPaper_TestQuestionModel.Describes;
                        exam_TestQuestionModel.IsMain = MyPaper_TestQuestionModel.IsMain;
                        exam_TestQuestionModel.AttachQuestion = MyPaper_TestQuestionModel.AttachQuestion;
                        exam_TestQuestionModel.SuspensionScore = MyPaper_TestQuestionModel.SuspensionScore;
                        exam_TestQuestionModel.LateScore = MyPaper_TestQuestionModel.LateScore;
                        exam_TestQuestionModel.StopScore = MyPaper_TestQuestionModel.StopScore;
                        exam_TestQuestionModel.SubmitScore = MyPaper_TestQuestionModel.SubmitScore;
                        exam_TestQuestionModel.Percent = MyPaper_TestQuestionModel.Percent;
                        exam_TestQuestionModel.TotalScore = MyPaper_TestQuestionModel.TotalScore;
                        exam_TestQuestionModel.CreateTime = DateTime.Now;
                        exam_TestQuestionModel.UpdateTime = DateTime.Now;
                        exam_TestQuestionModel.Roles = MyPaper_TestQuestionModel.Roles;
                        exam_TestQuestionModel.PaperTestQuestionId = MyPaper_TestQuestionModel.Id;
                        var lastId = MySQLExt.InsertIdentityIndex<Exam_TestQuestionModel>(conn, exam_TestQuestionModel);
                        exam_TestQuestionModel.Id = lastId;
                        if (MyexamModel.Exam_Questions==null)
                            MyexamModel.Exam_Questions=new List<Exam_TestQuestionModel>();
                        if (!MyexamModel.Exam_Questions.Any(model => model.Equals(exam_TestQuestionModel)))
                            MyexamModel.Exam_Questions.Add(exam_TestQuestionModel);
                    }
                }
                return Task.CompletedTask;
            }
            catch(Exception ex)
            {
                return null;
            }
        }
    }
}
